#ifndef _PID_H
#define _PID_H

#define LIMIT_MIN_MAX(x, M1, M2)                                                   \
  (x) = (M1 < M2) ? (((x) <= (M1)) ? (M1) : (((x) >= (M2)) ? (M2) : (x)))          \
                  : (((x) <= (M2)) ? (M2) : (((x) >= (M1)) ? (M1) : (x)))

#define v_DATA_MAX 2.0f

/**
  * @struct pid_struct_t
  * @brief struct of pid parameters
  */
typedef struct _pid_struct_t
{
  float kp;         ///< Kp
  float ki;         ///< Ki
  float kd;         ///< Kd
  float i_max;      ///< limit maximum of absolute value of integral
  float out_max;    ///< limit maximum of absolute value of output
  float k_deadband; ///< set the deadband
  
  int deadband_zero_output;
  float err[2];     ///< error and last error

  float p_out;
  float i_out;
  float d_out;
}pid_struct_t;


void pit_init(void);              
void pid_reset(pid_struct_t * pid);

float pid_calc(pid_struct_t *pid, float ref, float cur);


extern const pid_struct_t temp_pid_init_val;
extern pid_struct_t pid_temp_struct;
#endif
